﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserDataSet.aspx.cs" Inherits="SysManager_UserDataSet" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="../js/jquery/jquery-1.8.1.min.js" type="text/javascript"></script>
    <script src="../My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <link href="../css/btnsty.css" rel="stylesheet" type="text/css" />
    <link href="../css/global.css" rel="stylesheet" type="text/css" />
    <link href="../css/editform.css" rel="stylesheet" type="text/css" />
    <script src="../js/bootstrap-treeview.js" type="text/javascript"></script>
    <script src="../js/config.js" type="text/javascript"></script>
    <link href="../css/msgsty.css" rel="stylesheet" type="text/css" />
    <script src="../mobile/js/Toast.js" type="text/javascript"></script>
    <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <title>用户数据权限设置</title>
    <style>
        #add_div
        {
            height: 100%;
            width: 100%;
            padding-top: 50%;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            loduserlist("");
            //lodstocklist($.trim($("#txtstockname").val()));

            $("#btnstock").live("click", function () {
                lodstocklist($.trim($("#txtstockname").val()), $('#ListBox1 option:selected').val());
            });
            $("#btnsource").live("click", function () {
                loduserright($.trim($("#txtsource").val()), $('#ListBox1 option:selected').val());
            });
            $("#btnuser").live("click", function () {
                loduserlist($.trim($("#txtuser").val()));
            });
            $(".a_btn").live("click", function () {
                //alert($(this).attr("sty"));
                if ($('#ListBox1 option:selected').val() == undefined) {
                    showtoast("请选择用户", null, null, null);
                    return;
                }
                if ($(this).attr("sty") == "1") {
                    //添加所有
                    $("#q_Msgbox2").show();
                    for (var i = 0; i < $('#ListBox2 option').length; i++) {
                        //alert($('#ListBox2 option')[i].value);
                        AddUserRight($('#ListBox1 option:selected').val(), $('#ListBox2 option')[i].value, $('#ListBox2 option')[i].text)
                    }
                    $("#q_Msgbox2").hide();

                } else if ($(this).attr("sty") == "2") {
                    if ($('#ListBox2 option:selected').val() == undefined) {
                        showtoast("请选择要分配的权限", null, null, null);
                        return;
                    }
                    //添加当前
                    AddUserRight($('#ListBox1 option:selected').val(), $('#ListBox2 option:selected').val(), $('#ListBox2 option:selected').text())
                } else if ($(this).attr("sty") == "3") {
                    //删除当前
                    DelUserRight($('#ListBox3 option:selected').val());
                } else {
                    //删除所有
                    $("#q_Msgbox2").show();
                    for (var i = 0; i < $('#ListBox3 option').length; i++) {
                        //alert($('#ListBox2 option')[i].value);
                        DelUserRight($('#ListBox3 option')[i].value);
                    }
                    $("#q_Msgbox2").hide();
                }
            });

            $("#ListBox1").change(function () {
                //alert($('#ListBox1 option:selected').val());
                loduserright($.trim($("#txtsource").val()), $('#ListBox1 option:selected').val());
                lodstocklist($.trim($("#txtstockname").val()), $('#ListBox1 option:selected').val());
            });
        });

        function AddUserRight(uid, rid, rname) {
            $.post(url_path + "/UserDataSet.aspx",
                    { aciton: 'AddUserRight', userid: uid, sourceid: rid, sourcename: rname },
                     function (data) {
                         var msg = $.trim(data);
                         if (msg == "ERROR") {
                             //showtoast("添加失败！", null, null, null);
                         } else {
                             loduserright($.trim($("#txtsource").val()), $('#ListBox1 option:selected').val());
                             lodstocklist($.trim($("#txtstockname").val()), $('#ListBox1 option:selected').val());
                         }
                     });
        }
        function DelUserRight(val) {
            $.post(url_path + "/UserDataSet.aspx",
                    { aciton: 'DelUserRight', rid: val },
                     function (data) {
                         var msg = $.trim(data);
                         if (msg == "ERROR") {
                             //showtoast("删除失败！", null, null, null);
                         } else {
                             loduserright($.trim($("#txtsource").val()), $('#ListBox1 option:selected').val());
                             lodstocklist($.trim($("#txtstockname").val()), $('#ListBox1 option:selected').val());
                         }
                     });
        }
        function loduserlist(Username) {
            //加载用户
            $.post(url_path + "/UserDataSet.aspx",
                    { aciton: 'GetUserList',username: Username },
                     function (data) {
                         var msg = $.trim(data);
                         var html = "";
                         if (msg == "NO_DATA") {

                         } else {
                             var orderObj = JSON.parse(msg);
                             for (var i = 0; i < orderObj.length; i++) {
                                 html += "<option value='" + orderObj[i].userid + "'>" + orderObj[i].username + "</option>"
                             }
                             $("#ListBox1").html(html);
                         }
                     });
        }
        function lodstocklist(val, uid) {
            //加载店仓
            $("#q_Msgbox").show();
            $.post(url_path + "/UserDataSet.aspx",
                    { aciton: 'GetStockList', stockname: val, userid: uid },
                     function (data) {
                         var msg = $.trim(data);
                         if (msg == "NO_DATA") {
                             html = "<option value='0'>暂无数据...</option>"
                         } else {
                             var orderObj = JSON.parse(msg);
                             var html = "";
                             for (var i = 0; i < orderObj.length; i++) {
                                 html += "<option value='" + orderObj[i].stockid + "'>" + orderObj[i].stockname + "</option>"
                             }
                         }
                         $("#ListBox2").html(html);
                         $("#q_Msgbox").hide();
                     });
        }

        function loduserright(val, uid) {
            //加载店仓
            $.post(url_path + "/UserDataSet.aspx",
                    { aciton: 'GetUserRights', userid: uid, source: val },
                     function (data) {
                         var msg = $.trim(data);
                         var html = "";
                         if (msg == "NO_DATA") {
                             html = "<option value='0'>待分配...</option>"
                         } else {
                             var orderObj = JSON.parse(msg);
                             for (var i = 0; i < orderObj.length; i++) {
                                 html += "<option value='" + orderObj[i].rid + "'>" + orderObj[i].sourcename + "</option>"
                             }
                         }
                         $("#ListBox3").html(html);
                     });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div class="rptTitle">
            <b>用户数据权限设置</b>
        </div>
        <div class="param_div">
            <div id="Div2" style="-moz-border-radius: 15px; border-radius: 15px; margin: 5px;
                background-color: #ededed; padding: 8px; font-size: 15px; color: #8d8d8d;">
                <div class="row">
                    <div class="col-sm-4" style="width: 300px;">
                        <span>用户列表</span>
                        <div>
                            <asp:ListBox ID="ListBox1" class="ipt" Width="100%" Height="400" runat="server">
                                <asp:ListItem Text="1" Value="0">加载数据...</asp:ListItem>
                            </asp:ListBox>
                        </div>
                        <div style="padding: 8px 5px;">
                            <input id="txtuser" type="text" placeholder="输入内容模糊搜索" />&nbsp; <a id="btnuser"
                                class="button x_small medium-blue" href="#">查找</a>
                        </div>
                    </div>
                    <div class="col-sm-4" style="width: 300px;">
                        <span>待分配的数据列表</span>
                        <div>
                            <asp:ListBox ID="ListBox2" class="ipt" Width="100%" Height="400" runat="server">
                                <asp:ListItem Text="1" Value="0">加载数据...</asp:ListItem>
                            </asp:ListBox>
                        </div>
                        <div style="padding: 8px 5px;">
                            <input id="txtstockname" type="text" placeholder="输入内容模糊搜索" />&nbsp; <a id="btnstock"
                                class="button x_small medium-blue" href="#">查找</a>
                        </div>
                    </div>
                    <div class="col-sm-4" style="width: 100px; height: 400px;">
                        <div id="add_div">
                            <div>
                                <a id="btnaddall" href="#" sty="1" class="a_btn button small medium-blue" runat="server">
                                    全部></a></div>
                            <div style="padding-top: 20px;">
                                <a id="btnadd" href="#" sty="2" class="a_btn button small medium-blue" runat="server">
                                    添加></a></div>
                            <div style="padding-top: 20px;">
                                <a id="btndel" href="#" sty="3" class="a_btn button small medium-red" runat="server">
                                    删除<</a></div>
                            <div style="padding-top: 20px;">
                                <a id="btndelall" href="#" sty="4" class="a_btn button small medium-red" runat="server">
                                    全部<</a></div>
                        </div>
                    </div>
                    <div class="col-sm-4" style="width: 300px;">
                        <span>已拥有的数据列表</span>
                        <div>
                            <asp:ListBox ID="ListBox3" class="ipt" Width="100%" Height="400" runat="server">
                                <asp:ListItem Text="1" Value="0">待添加...</asp:ListItem>
                            </asp:ListBox>
                        </div>
                        <div style="padding: 8px 5px;">
                            <input id="txtsource" type="text" placeholder="输入内容模糊搜索" />&nbsp; <a id="btnsource"
                                class="button x_small medium-blue" href="#">查找</a>
                        </div>
                    </div>
                </div>
                <div>
                    <span style="color: #ff0000;"><strong>&nbsp; &nbsp; 操作说明：</strong> </span>点击用户列表加载相应的数据权限和待添加的数据。
                </div>
            </div>
        </div>
    </div>
    <div class="zeng_msgbox_layer_wrap" id="q_Msgbox" style="top: 109px; display: none;
        z-index: 998;">
        <span class="zeng_msgbox_layer" style="z-index: 998;" id="mode_tips_v2"><span class="gtl_ico_clear">
        </span><span class="gtl_ico_loading"></span>正在加载中，请稍后...<span class="gtl_end"></span></span></div>
    <div class="zeng_msgbox_layer_wrap" id="q_Msgbox2" style="top: 109px; display: none;
        z-index: 100000;">
        <span class="zeng_msgbox_layer" style="z-index: 100000;" id="Span1"><span class="gtl_ico_clear">
        </span><span class="gtl_ico_loading"></span>正在处理中，请稍后...<span class="gtl_end"></span></span></div>
    </form>
</body>
</html>
